#include "sensor_reader.h"
#include "timer_utils.h"
#include <stdlib.h>

// 模拟传感器数据
static float s_cabinet_temp = 25.0f;
static float s_material_temp = 25.0f;
static uint32_t s_motor_current = 0;
static bool s_temp_ok = true;
static bool s_current_ok = true;

void sensor_init(void) {
    printf("Sensors initialized\n");
}

// 模拟传感器数据变化
static void simulate_sensors(void) {
    static uint32_t last_update = 0;
    uint32_t now = get_system_time_ms();
    
    if (now - last_update > 1000) {
        last_update = now;
        
        // 小范围随机波动模拟
        s_cabinet_temp += ((rand() % 200) - 100) / 100.0f;
        s_material_temp += ((rand() % 200) - 100) / 100.0f;
        s_motor_current = 500 + (rand() % 200) - 100;
    }
}

void sensor_read(SensorData* data) {
    if (data == NULL) return;
    
    simulate_sensors();
    
    data->cabinet_temp = s_cabinet_temp;
    data->material_temp = s_material_temp;
    data->motor_current = s_motor_current;
    data->temp_sensor_ok = s_temp_ok;
    data->current_sensor_ok = s_current_ok;
}
